﻿Public Class CommandToIconConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        If targetType IsNot GetType(ImageSource) Then _
            Throw New InvalidOperationException("La cible doit être de type System.Windows.Media.ImageSource")
        If Not TypeOf (value) Is ViewModels.ViewModelCommand Then _
            Throw New InvalidOperationException("La cible doit être de type TauxGaranti.ViewModels.ViewModelCommand")
        Try
            If value.GetType Is GetType(ViewModels.ViewModelCmdEncoursCorresp) Then
                Return createBitmapImage(New Uri("../../Images/grid.png", UriKind.Relative))
            ElseIf value.GetType Is GetType(ViewModels.ViewModelCmdEncoursImport) Then
                Return createBitmapImage(New Uri("../../Images/calculator.png", UriKind.Relative))
            ElseIf value.GetType Is GetType(ViewModels.ViewModelCmdEncoursRetrait) Then
                Return createBitmapImage(New Uri("../../Images/current-work.png", UriKind.Relative))
            Else
                Return createBitmapImage(New Uri("../../Images/chart_pie.png", UriKind.Relative))
            End If
        Catch ex As Exception
            Return DependencyProperty.UnsetValue
        End Try
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function

    Private Function createBitmapImage(ByVal Uri As Uri) As BitmapImage
        Dim result As BitmapImage = New BitmapImage
        result.BeginInit()
        result.UriSource = Uri
        result.EndInit()
        Return result
    End Function

End Class
